using System.Collections.Generic;

public class MissionTargetKillNeedTypeMob : MissionTargetBase
{
	public List<int> needNumberSkinMob;

	public List<SectorMobManager> neededSectors = new List<SectorMobManager>();

	public List<EnemyBehavior> listTrackingEnemy = new List<EnemyBehavior>();

	private void OnDisable()
	{
		if (curParametr.isStarted)
		{
			OnStopTarget();
		}
	}

	protected override void OnShowStartMsg()
	{
		MessageManager.instance.CreateMessage(base.messageStart, IdClForMsg.levelUp, TypeAnimMessage.longTimeMessage, 5f);
	}

	protected override bool OnStartTarget()
	{
		if (!base.OnStartTarget())
		{
			return false;
		}
		ManagerMissions.killMob += OnKillMOB;
		curParametr.UpdateValue();
		if (SearchEnemies.instance != null)
		{
			if (neededSectors.Count > 0)
			{
				BCWDebug.Log("NEEDED SECTOR");
				for (int i = 0; i < needNumberSkinMob.Count; i++)
				{
					SearchEnemies.instance.AddNeededSectorsWeithSkin(neededSectors, needNumberSkinMob[i]);
				}
			}
			else
			{
				BCWDebug.Log("ALL SECTORS");
				for (int j = 0; j < needNumberSkinMob.Count; j++)
				{
					SearchEnemies.instance.AddSectorsForNumberSkin(needNumberSkinMob[j]);
				}
			}
			SearchEnemies.instance.enableArrow = true;
		}
		return true;
	}

	public override void OnStopTarget()
	{
		base.OnStopTarget();
		ManagerMissions.killMob -= OnKillMOB;
		if (SearchEnemies.instance != null)
		{
			SearchEnemies.instance.enableArrow = false;
			SearchEnemies.instance.RemoveAllArrow();
		}
	}

	public override void OnUpdateTarget()
	{
		if (!(MobSpawnController.instance != null))
		{
			return;
		}
		for (int i = 0; i < MobSpawnController.instance.MobsList.Count; i++)
		{
			EnemyBehavior enemyBehavior = MobSpawnController.instance.MobsList[i];
			if (ContainSkin(enemyBehavior.skinNumber))
			{
				if (neededSectors.Count > 0)
				{
					if (!ContainEnemy(enemyBehavior))
					{
						listTrackingEnemy.Add(enemyBehavior);
						SearchEnemies.instance.AddTargetForTracking(enemyBehavior.gameObject);
					}
				}
				else if (!ContainEnemy(enemyBehavior))
				{
					listTrackingEnemy.Add(enemyBehavior);
					SearchEnemies.instance.AddTargetForTracking(enemyBehavior.gameObject);
				}
			}
			else if (ContainEnemy(enemyBehavior))
			{
				listTrackingEnemy.Remove(enemyBehavior);
				SearchEnemies.instance.RemoveTargetForTracking(enemyBehavior.gameObject);
			}
		}
	}

	private bool ContainSector(SectorMobManager sectorMobManager)
	{
		foreach (SectorMobManager neededSector in neededSectors)
		{
			if (sectorMobManager.name == neededSector.name)
			{
				return true;
			}
		}
		return false;
	}

	private bool ContainEnemy(EnemyBehavior eb)
	{
		for (int i = 0; i < listTrackingEnemy.Count; i++)
		{
			if (listTrackingEnemy[i].Equals(eb))
			{
				return true;
			}
		}
		return false;
	}

	private bool ContainSkin(int numb)
	{
		for (int i = 0; i < needNumberSkinMob.Count; i++)
		{
			if (needNumberSkinMob[i].Equals(numb))
			{
				return true;
			}
		}
		return false;
	}

	private void OnKillMOB(EnemyBehavior curEnemy)
	{
		if (!curParametr.isComplete && needNumberSkinMob.Contains(curEnemy.skinNumber))
		{
			curCountTarget++;
			curParametr.UpdateValue();
			if (TargetIsComplete())
			{
				CompleteTarget();
			}
		}
	}
}
